package com.licw.controller.admin;

import com.licw.dto.SetmealDTO;
import com.licw.dto.SetmealPageQueryDTO;
import com.licw.result.PageResult;
import com.licw.result.Result;
import com.licw.service.SetmealService;
import com.licw.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 套餐管理
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Resource
    private SetmealService setmealService;

    @PostMapping
    @ApiOperation("新增套餐")
    public Result<Object> add(@RequestBody SetmealDTO setmealDTO){
        log.info("新增套餐：{}",setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult<SetmealVO>> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("分页查看套餐：{}", setmealPageQueryDTO);
        PageResult<SetmealVO> page = setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(page);
    }

    /**
     * 根据id查询套餐
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> list(@PathVariable Long id){
        log.info("根据id查询套餐：{}",id);
        SetmealVO setmealVO = setmealService.getVOById(id);
        return Result.success(setmealVO);
    }

    /**
     * 批量删除套餐
     */
    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result<Object> deleteById(@RequestParam List<Long> ids){
        log.info("批量删除套餐：{}",ids);
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 修改套餐
     */
    @PutMapping
    @ApiOperation("修改套餐")
    public Result<Object> edit(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐：{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

    /**
     * 停售/起售套餐
     */
    @PostMapping("/status/{status}")
    @ApiOperation("停售/起售套餐")
    public Result<Object> setStatus(@PathVariable Integer status, Long id){
        log.info("停售/起售套餐：{}", id);
        setmealService.setStatus(status, id);
        return Result.success();
    }

}
